using UnityEngine;
using System.Diagnostics;

namespace FibMatrix
{
    [FM_Mono.IgnoreGen]
    public class RealTimer
    {
        // Stopwatch在微信小游戏性能很差，底层用clocktime，获取一次要毫秒级。用Time.realtimeSinceStartup没问题
        
        // private static Stopwatch _watcher;
        private static float _resetTime;
        
        public static void Reset()
        {
            _resetTime = Time.realtimeSinceStartup;
            //     if (_watcher == null)
            //     {
            //         _watcher = Stopwatch.StartNew();
            //     }
            //     else
            //     {
            //         _watcher.Reset();
            //         _watcher.Start();
            //     }
        }

        public static long elapsedMilliseconds
        {
            get { return (long)((Time.realtimeSinceStartup - _resetTime) * 1000); }
        }

        public static double elapsedSeconds
        {
            get { return Time.realtimeSinceStartup - _resetTime; }
        }
        
        // Real elapsed time since frame begin
        public static float frameDuration => Time.realtimeSinceStartup - Time.unscaledTime;
    }
}